import { S } from '../../s';
import { IPSAppDEField } from '../../app/dataentity/ipsapp-defield';
import { IPSControl } from '../ipscontrol';
import { IPSDEForm } from './ipsdeform';
import { IPSDEFormItemUpdate } from './ipsdeform-item-update';
import { IPSDEFormMDCtrl } from './ipsdeform-mdctrl';
import { PSDEFormBaseGroupPanelImpl } from './psdeform-base-group-panel-impl';

export class PSDEFormMDCtrlImpl
  extends PSDEFormBaseGroupPanelImpl
  implements IPSDEFormMDCtrl
{
  get buildInActions(): 1 | 2 | 4 {
    return this.M.buildInActions != null ? this.M.buildInActions : 0;
  }

  protected contentpscontrol: IPSControl;
  getContentPSControl(): IPSControl | null {
    return (
      this.contentpscontrol ||
      (this.contentpscontrol = this.fillObjectModel(
        S._214,
        this.M.getContentPSControl,
        S._33c,
      ) as IPSControl)
    );
  }

  get contentType(): 'LIST' | 'FORM' | 'GRID' | 'DATAVIEW' | 'REPEATER' {
    return this.M.contentType;
  }

  get fieldName(): string {
    return this.M.fieldName;
  }

  protected psappdefield: IPSAppDEField;
  getPSAppDEField(): IPSAppDEField | null {
    return (
      this.psappdefield ||
      (this.psappdefield = this.fillObjectModel(
        S._1,
        this.M.getPSAppDEField,
        S._2e4,
      ) as IPSAppDEField)
    );
  }

  protected psdeformitemupdate: IPSDEFormItemUpdate;
  getPSDEFormItemUpdate(): IPSDEFormItemUpdate | null {
    if (this.psdeformitemupdate != null) return this.psdeformitemupdate;
    const value = this.M.getPSDEFormItemUpdate;
    if (value == null) {
      return;
    }
    const ipsdeform = this.getParentPSModelObject(S._23d) as IPSDEForm;
    if (ipsdeform != null) {
      this.psdeformitemupdate = ipsdeform.findPSDEFormItemUpdate(value);
    }
    return this.psdeformitemupdate;
  }

  get resetItemName(): string {
    return this.M.resetItemName;
  }

  protected resetitemnames: string[];
  getResetItemNames(): string[] | null {
    if (this.resetitemnames == null) {
      const value = this.M.resetItemNames;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: string[] = [];
      for (let i = 0; i < arrayNode.length; i++) {
        list.push(arrayNode[i]);
      }
      this.resetitemnames = list;
    }
    return this.resetitemnames.length == 0 ? null : this.resetitemnames;
  }

  get one2OneForm(): boolean {
    return this.M.one2OneForm != null ? this.M.one2OneForm : false;
  }
  get cls(): string {
    return 'PSDEFormMDCtrlImpl';
  }
  instanceof(cls: string): boolean {
    if (cls == S._bb) return true;
    return super.instanceof(cls);
  }
}
